package cn.com.roc.main.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
import com.sencha.gxt.widget.core.client.box.MessageBox;
import com.sencha.gxt.widget.core.client.button.TextButton;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class App implements EntryPoint {

	private final GreetingServiceAsync greetingService = GWT
			.create(GreetingService.class);

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		TextButton button = new TextButton("Hello");
		button.addSelectHandler(new SelectHandler() {

			@Override
			public void onSelect(SelectEvent event) {
				greetingService.greetServer("Hello",
						new AsyncCallback<String>() {

							@Override
							public void onSuccess(String result) {
								MessageBox box = new MessageBox("success",
										result);
								box.show();
							}

							@Override
							public void onFailure(Throwable caught) {
								AlertMessageBox box = new AlertMessageBox(
										"error", caught.getMessage());
								box.show();
							}
						});
			}
		});
		RootPanel.get().add(button);
	}
}
